<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"  %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	
</head>
<body class="no-skin">
	<div class="main-content">
				<!-- #section:basics/content.breadcrumbs -->
				<div class="breadcrumbs" id="breadcrumbs">
					<script type="text/javascript">
						try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
					</script>

					<ul class="breadcrumb">
						<li>
							<i class="ace-icon fa fa-home home-icon"></i>
							<a href="#">Home</a>
						</li>
						<li>
							<a href="#">Tables</a>
						</li>
						<li class="active">Simple &amp; Dynamic</li>
					</ul><!-- /.breadcrumb -->

					<!-- #section:basics/content.searchbox -->
					<div class="nav-search" id="nav-search">
						<form class="form-search">
							<span class="input-icon">
								<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
								<i class="ace-icon fa fa-search nav-search-icon"></i>
							</span>
						</form>
					</div><!-- /.nav-search -->

					<!-- /section:basics/content.searchbox -->
				</div>

				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					<div class="ace-settings-container" id="ace-settings-container">
						<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
							<i class="ace-icon fa fa-cog bigger-150"></i>
						</div>

						<div class="ace-settings-box clearfix" id="ace-settings-box">
							<div class="pull-left width-50">
								<!-- #section:settings.skins -->
								<div class="ace-settings-item">
									<div class="pull-left">
										<select id="skin-colorpicker" class="hide">
											<option data-skin="no-skin" value="#438EB9">#438EB9</option>
											<option data-skin="skin-1" value="#222A2D">#222A2D</option>
											<option data-skin="skin-2" value="#C6487E">#C6487E</option>
											<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
										</select>
									</div>
									<span>&nbsp; Choose Skin</span>
								</div>

								<!-- /section:settings.skins -->

								<!-- #section:settings.navbar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar" />
									<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
								</div>

								<!-- /section:settings.navbar -->

								<!-- #section:settings.sidebar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar" />
									<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
								</div>

								<!-- /section:settings.sidebar -->

								<!-- #section:settings.breadcrumbs -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs" />
									<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
								</div>

								<!-- /section:settings.breadcrumbs -->

								<!-- #section:settings.rtl -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" />
									<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
								</div>

								<!-- /section:settings.rtl -->

								<!-- #section:settings.container -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container" />
									<label class="lbl" for="ace-settings-add-container">
										Inside
										<b>.container</b>
									</label>
								</div>

								<!-- /section:settings.container -->
							</div><!-- /.pull-left -->

							<div class="pull-left width-50">
								<!-- #section:basics/sidebar.options -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-hover" />
									<label class="lbl" for="ace-settings-hover"> Submenu on Hover</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-compact" />
									<label class="lbl" for="ace-settings-compact"> Compact Sidebar</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-highlight" />
									<label class="lbl" for="ace-settings-highlight"> Alt. Active Item</label>
								</div>

								<!-- /section:basics/sidebar.options -->
							</div><!-- /.pull-left -->
						</div><!-- /.ace-settings-box -->
					</div><!-- /.ace-settings-container -->

					<!-- /section:settings.box -->
					<div class="page-content-area">
						<div class="page-header">
							<h1>
								课程信息
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									Subject Message
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12">
										
										<div class="row">
											
												<!-- <div class="col-xs-6">
													<button type="button" class="btn btn-primary" id="bath_delete_Btn">
													  <span class="glyphicon glyphicon-plus" aria-hidden="true">批量删除</span>
													</button>
												</div> -->
										</div>
										
										
										<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th align="center"><button type="button" class="btn btn-info btn-sm" id="saveExamTest">增加考题</button></th>
													<th>编号</th>										
													<th>题干</th>
													<th>选项A</th>
													<th>选项B</th>
													<th>选项C</th>
													<th>选项D</th>
													<th>答案</th>
													<th>题目分数</th>
													<th>操作</th>
												</tr>
											</thead>

											<tbody>
													<c:forEach items="${ExamTestList.dates}" var="examTest">			
												<tr>
													<td class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace">
															<span class="lbl"></span>
														</label>
													</td>
													<td>${examTest.id }</td>
													<td>${examTest.content }</td>
													<td>${examTest.chooseA }</td>
													<td>${examTest.chooseB }</td>
													<td>${examTest.chooseC }</td>
													<td>${examTest.chooseD }</td>
													<td>${examTest.answer}</td>
													<td>${examTest.examTestType.testTypeScore}</td>
													<td>
														<button type="button" class="btn btn-primary btn-xs showTest" show_id="${examTest.id }"  title="查看考题">
															<span class="ace-icon fa fa-comment" aria-hidden="true"></span>
														</button>
														<button type="button" class="btn btn-primary btn-xs updateTest" update_id="${examTest.id }"  title="修改考题">
															<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
														</button>
														<button type="button" class="btn btn-danger btn-xs deleteTest" delete_id="${examTest.id }"   title="删除考题">
															<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
														</button>
													</td>
												</tr>
											</c:forEach>
											</tbody>
										</table>
										<pg:pager url="ExamTest" items="${ExamTestList.totalSize}" export="currentPageNumber=pageNumber" maxPageItems="5">   
											  <pg:first>   
											    <a href="${pageUrl}">首页</a>   
											  </pg:first>   
											  <pg:prev>   
											    <a href="${pageUrl }">上一页</a>   
											  </pg:prev>   
											  <pg:pages>   
											    <c:choose>   
											      <c:when test="${currentPageNumber eq pageNumber}">   
											        <font color="red">${pageNumber }</font>   
											      </c:when>   
											      <c:otherwise>   
											        <a href="${pageUrl }">${pageNumber }</a>   
											      </c:otherwise>   
											    </c:choose>   
											  </pg:pages>   
											  <pg:next>   
											    <a href="${pageUrl }">下一页</a>   
											  </pg:next>   
											  <pg:last>   
											    <a href="${pageUrl }">尾页</a>   
											  </pg:last>   
										</pg:pager>   
										
									</div><!-- /.span -->
								</div><!-- /.row -->
							<div class="hr hr-18 dotted hr-double"></div>
						</div><!--col-xs-12-->
					</div><!--row-->
				</div><!-- /.page-content-area -->
			</div><!-- /.page-content -->
		</div><!-- /.main-content -->
		
		
		<!-- 查询详细的信息 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="showTestModal">
			  <div class="modal-dialog" role="document">
				    <div class="modal-content">
				    
					      <div class="modal-header">
						        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						        <h4 class="modal-title">查看考题</h4>
					      </div>
					      
					      <div class="modal-body">
					        	<label>试题科目：&nbsp;</label><span class="sub-name"></span><br>
					        	<label>试题：&nbsp;</label><span class="content"></span>&nbsp;&nbsp;——&nbsp;&nbsp;(<span class="test-type"></span>,每题<span class="test-type-score"></span>分)<br>
					        	<label>A：&nbsp;</label><span class="choose-a"></span><br>
					        	<label>B：&nbsp;</label><span class="choose-b"></span><br>
					        	<label>C：&nbsp;</label><span class="choose-c"></span><br>
					        	<label>D：&nbsp;</label><span class="choose-d"></span><br>
					        	<label style="font-weight:bold;">答案:&nbsp;&nbsp;</label><span class="answer" style="font-weight:bold;"></span>
					      </div>
					      
					      <div class="modal-footer">
						        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>	
					      </div>
				    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		
		
		
		<!-- 添加考题 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="addTestModal">
			  <div class="modal-dialog" role="document">
				    <div class="modal-content">
				    
					      <div class="modal-header">
						        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						        <h4 class="modal-title">添加考题</h4>
					      </div>
					      
					      <div class="modal-body" >
						      	<form id="addTestForm" method="post" class="form-horizontal">
						      		<div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">科目</label>
									    <div class="col-sm-6">
									      <select class="form-control" id="addTest_SubName" name="subjects.subId"></select>
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">试题类型</label>
									    <div class="col-sm-6">
									      <select class="form-control" id="addTest_testType" name="examTestType.id"></select>
									    </div>
									    <!-- <label for="empName_add_input" class="col-sm-2 control-label">分数:</label>
									    <div class="col-sm-2">
				      						<p class="form-control-static" id="empName_add_static"></p>
				    					</div> -->
									   
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">题干</label>
									    <div class="col-sm-10">
									      <textarea name="content" class="form-control" rows="3"></textarea>
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项A</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseA" class="form-control" id="inputEmail3" placeholder="选项A">
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项B</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseB" class="form-control" id="inputEmail3" placeholder="选项B">
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项C</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseC" class="form-control" id="inputEmail3" placeholder="选项C">
									    </div>
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项D</label>
									    <div class="col-sm-10">
									     	<input type="text" name="chooseD" class="form-control" id="inputEmail3" placeholder="选项D">
									    </div>
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">答案</label>
									    <div class="col-sm-10">
										     <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox1" value="A">A
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox2" value="B">B
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox3" value="C">C
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox3" value="D">D
											 </label>
									    </div>
								    </div>		        	
						        </form>
					      </div>
					      
					      <div class="modal-footer">
						        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>	
						        <button type="button" class="btn btn-primary" data-dismiss="modal" id="addTestSaveBtn">保存</button>	<
					      </div>
				    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		
		
		<!-- 修改考题 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="updateTestModal">
			  <div class="modal-dialog" role="document">
				    <div class="modal-content">
				    
					      <div class="modal-header">
						        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						        <h4 class="modal-title">修改考题</h4>
					      </div>
					      
					      <div class="modal-body" >
						      	<form id="updateTestForm" class="form-horizontal">
						      		<div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">科目</label>
									    <div class="col-sm-6">
									      <select class="form-control" id="updateTest_SubName" name="subjects.subId"></select>
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">试题类型</label>
									    <div class="col-sm-6">
									      <select class="form-control" id="updateTest_testType" name="examTestType.id"></select>
									    </div>
									    <label for="empName_add_input" class="col-sm-2 control-label">分数:</label>
									    <div class="col-sm-2">
				      						<p class="form-control-static" id="empName_update_static"></p>
				    					</div>
									   
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">题干</label>
									    <div class="col-sm-10">
									      <textarea name="content" class="form-control" id="update_content" rows="3"></textarea>
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项A</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseA" class="form-control" id="update_chooseA" placeholder="选项A">
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项B</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseB" class="form-control" id="update_chooseB" placeholder="选项B">
									    </div>
								    </div>
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项C</label>
									    <div class="col-sm-10">
									      	<input type="text" name="chooseC" class="form-control" id="update_chooseC" placeholder="选项C">
									    </div>
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">选项D</label>
									    <div class="col-sm-10">
									     	<input type="text" name="chooseD" class="form-control" id="update_chooseD" placeholder="选项D">
									    </div>
								    </div>
								    
								    
								    <div class="form-group">
									    <label for="inputEmail3" class="col-sm-2 control-label">答案</label>
									    <div class="col-sm-10">
										     <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox1" value="A">A
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox2" value="B">B
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox3" value="C">C
											 </label>
											 <label class="checkbox-inline">
												  <input type="checkbox" name="answer" id="inlineCheckbox3" value="D">D
											 </label>
									    </div>
								    </div>		        	
						        </form>
						        <div class="modal-footer">
							        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>	
							        <button type="button" class="btn btn-primary" data-dismiss="modal" id="updateTestSaveBtn">修改</button>	<
						      	</div>
					      </div>
					      
				    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		
		
		<script type="text/javascript">
function getTestById(id){
	$.ajax({
		url:"${pageContext.request.contextPath }/ExamTests/getTestById",
		type:"POST",
		data:"testId="+id,
		dataType:"json",
		success:function(result){
			$("#showTestModal .sub-name").text(result.map.data.subName);
			$("#showTestModal .content").text(result.map.data.content);
			$("#showTestModal .test-type").text(result.map.data.examTestType.testType);
			$("#showTestModal .test-type-score").text(result.map.data.examTestType.testTypeScore);
			$("#showTestModal .choose-a").text(result.map.data.chooseA);
			$("#showTestModal .choose-b").text(result.map.data.chooseB);
			$("#showTestModal .choose-c").text(result.map.data.chooseC);
			$("#showTestModal .choose-d").text(result.map.data.chooseD);
			$("#showTestModal .answer").text(result.map.data.answer);
			/* $.each(result.map.answers,function(index,item){
				$("#showTestModal .answer").text(item);
			});  */
			/* for(var i=0;i<result.map.answers.length;i++){
				$("#showTestModal .answer").text(result.map.answers[i]+",");
			} */
		}
	});
}


//展示详细的数据信息
$(".showTest").click(function(){
	var testId=$(this).parent().siblings().eq(1).text();
	getTestById(testId);
	$("#showTestModal").modal({
			backdrop:"static"
	});
}); 


//点击弹出添加考题的模态框
$("#saveExamTest").click(function(){
	//科目信息
	getSubs("#addTest_SubName");
	//试题类型
	getTestTypes("#addTest_testType");
	
	$("#addTestModal").modal({
		backdrop:"static"
	});
})

//获取所有的科目信息
function getSubs(ele){
	$(ele).empty();
	$.ajax({
		url:"${pageContext.request.contextPath }/Subjects/getSubject",
		type:"GET",
		success:function(result){
			$.each(result.map.subjects,function(index,item){
				var options=$("<option></option>").append(item.name).attr("value",item.subId);
				options.appendTo(ele);
			});	
		}
	});
}

//获取所有的试题类型
function getTestTypes(ele){
	$(ele).empty();
	$.ajax({
		url:"${pageContext.request.contextPath }/TestType/getTestTypes",
		type:"GET",
		success:function(result){
			$.each(result.map.testTypes,function(index,item){
				var options=$("<option></option>").append(item.testType).attr("value",item.id);
				options.appendTo(ele);
			});
		}
	});
}

//保存功能
$("#addTestSaveBtn").click(function(){
	$.ajax({
		url:"${pageContext.request.contextPath }/ExamTests/saveExamTest",
		type:"POST",
		data:$("#addTestModal form").serialize(),
		success:function(result){
			$("#addTestModal").modal("hide");
			alert(result.message);
			window.location.reload();
		}
	});
})


/* //打开批量保存的模态框
$("#bath_add_Btn").click(function(){
	$("#uploadFileModal").modal({
		backdrop:"static"
});
	
});

//文件上传的样式控制
$("#uploadFile").ace_file_input({
	style:'well',
	btn_choose:'Drop files here or click to choose',
	btn_change:null,
	no_icon:'ace-icon fa fa-cloud-upload',
	droppable:true,
	thumbnail:'small',
	preview_error:function(filename,error_code){
		
	}
}).on('change',function(){
	
});

//ajxa请求批量添加学生
$("#upfileSaveBtn").click(function(){
	$.ajaxFileUpload({
		url:"${pageContext.request.contextPath }/ExamTests/uploadFile",
		secureuri:false,
		fileElementId:"uploadFile",
		dataType:"json",
		complete:function(data){
			
		},
		success:function(data,status){
			if(data.code==100){
				alert("处理成功");
			}
			else{
				alert("处理不成功");
			}
		},
		error:function(data,status,e){
			alert(e);
		}
	 })
})*/

//点击打开修改的模态框
$(".updateTest").click(function(){
	getSubs("#updateTest_SubName");
	getTestTypes("#updateTest_testType");
	$("#updateTestSaveBtn").attr("update_id",$(this).attr("update_id"));
	$.ajax({
		url:"${pageContext.request.contextPath }/ExamTests/getTestById",
		data:"testId="+$(this).attr("update_id"),
		type:"POST",
		success:function(result){
			$("#update_content").val(result.map.data.content);
			$("#update_chooseA").val(result.map.data.chooseA);
			$("#update_chooseB").val(result.map.data.chooseB);
			$("#update_chooseC").val(result.map.data.chooseC);
			$("#update_chooseD").val(result.map.data.chooseD);
			
			
			$.each(result.map.answers,function(index,item){
				 if(item=="A"){
					 $("#updateTestModal input[type='checkbox']").eq(0).prop("checked",true);
				 }
				 if(item=="B"){
					 $("#updateTestModal input[type='checkbox']").eq(1).prop("checked",true);
				 }
				 if(item=="C"){
					 $("#updateTestModal input[type='checkbox']").eq(2).prop("checked",true);
				 }
				 if(item=="D"){
					 $("#updateTestModal input[type='checkbox']").eq(3).prop("checked",true);
				 }
			})
		}
	});
	
	$("#updateTestModal").modal({
		backdrop:"static"
});
})

//点击更新的操作
$("#updateTestSaveBtn").click(function(){
	$.ajax({
		url:"${pageContext.request.contextPath }/ExamTests/updateTest/"+$(this).attr("update_id"),
		type:"POST",
		data:$("#updateTestModal form").serialize(),
		success:function(result){
			$("#addTestModal").modal("hide");
			alert(result.message);
			window.location.reload();
		}
	});
});

//删除操作
$(".deleteTest").click(function(){
	if(confirm("确认删除【"+$(this).attr("delete_id")+"】的员工吗？")){
	$.ajax({
		url:"${pageContext.request.contextPath }/ExamTests/deleteTest/"+$(this).attr("delete_id"),
		type:"POST",
		success:function(result){
			alert(result.message);
			window.location.reload();
		}
	});
	}
});



</script>	
</body>


</html>

